
use std::path::PathBuf;

use gfsc::*;

pub fn main() {
    if std::env::args().len() < 4 {
        println!("{} read_file_name idx where_is_router.json", std::env::args().nth(0).unwrap_or_default());
        return
    }

    let filename = std::env::args().nth(1).expect("no file given");
    let fidx = std::env::args().nth(2).expect("no idx given");
    let conf = std::env::args().nth(3).expect("no router.json given");

    let fpath = PathBuf::from(filename);
    let save_name = fpath.file_name().unwrap().to_string_lossy();

    let router = gfsc_new_router( conf.as_str() ).unwrap();
    let ihash = gfs_filename_hash(&save_name);    
    let idx = fidx.parse::<i32>().unwrap() ;

    // let read_url = router.get_reader_url(router.cur_dynasty, idx, ihash, &save_name).unwrap();    
    let f = gfsc_read_text(&router, router.cur_dynasty, idx, ihash, &save_name );
    let rt = tokio::runtime::Runtime::new().unwrap();
    let r = rt.block_on(f).unwrap();
    println!("{}", r);
    
}
 